package xcmg.device.util;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import xcmg.device.infra.StringUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Component
public class CompanyUtil {

  public final static String IMPORT_EXPORT_COM_NAME = "徐州工程机械集团进出口有限公司";

  public final static String ZL_COM_NAME = "徐州徐工智联物流服务有限公司";

  private static String WJ_ORG_ID = "214678683422556160";

  public static final String SWY_SAP_CODE = "2170";

  //矿机sap编码
  public static final String KJ_SAP_CODE = "2200";

  //挖机
  public static final String WJ_SAP_CODE = "2080";

  // 基础
  public static final String JC_SAP_CODE = "2100";

  //随车
  public static final String SC_SAP_CODE = "2050";

  public static final String TJ_SAP_CODE = "2130";
  //履带吊
  public static final String LVDAI_SAP_CODE = "2180";
  //重型
  public static final String ZX_SAP_CODE = "2013";

  //铲运
  public static final String CY_SAP_CODE = "2020";

  //进出口
  public static final String JCK_SAP_CODE = "4060";

  @Value("${sc.orgId:0}")
  public String SC_ORG_ID;

  @Value("${tj.orgId:0}")
  public String TJ_ORG_ID;

  @Value("${jck.orgId:0}")
  public String JCK_ORG_ID;


  @Value("${yn.orgId:594827698702909440}")
  public String YN;

  /**
   * SHELL_ORG_ID:company_info表中壳牌的org_id
   * SHELL_WJ_SUPPLIER_ORG_ID:挖机的供应商壳牌，company_supplier表中supplier_org_id的值
   */
  private static String SHELL_ORG_ID = "236125544796651520", SHELL_WJ_SUPPLIER_ORG_ID = "216598547884146688";

//  static {
//    Properties properties = new Properties();
//    try {
//      //获取当前类加载器
//      ClassLoader classLoader = CompanyUtil.class.getClassLoader();
//      //通过当前累加载器方法获得 文件db.properties的一个输入流
//      InputStream is = classLoader.getResourceAsStream("application.properties");
//      properties.load(is);
//
//      if (StringUtil.isNotEmpty(properties.getProperty("wj.orgId"))) {
//        WJ_ORG_ID = properties.getProperty("wj.orgId");
//      }
//
//    } catch (IOException ioe) {
//      ioe.printStackTrace();
//    }
//  }


  /**
   * 判断是否是挖机公司。用sapCode判断可以避免开发/测试/线上环境orgId不一致的问题
   *
   * @param sapCode
   * @return
   */
  public static boolean isWJSapCode(String sapCode) {
    return WJ_SAP_CODE.equals(sapCode);
  }

  public static boolean isWJ(String orgId) {
    return WJ_ORG_ID.equals(orgId);
  }

  /**
   * @Des 是否为矿机主机厂
   * @Date 2020/11/16 10:20
   * @Author wangzhaoyu
   * @Param [sapCode]
   * @Return boolean
   */
  public static boolean isKJ(String sapCode){
    if(StringUtils.isEmpty(sapCode)){
      return false;
    }
    return sapCode.equals(KJ_SAP_CODE);
  }

  public static boolean isSWY(String sapCode) {
    return SWY_SAP_CODE.equals(sapCode);
  }

  /**
   * 是否徐工基础
   *
   * @param sapCode
   * @return
   */
  public static boolean isJC(String sapCode) {
    return JC_SAP_CODE.equals(sapCode);
  }

  /**
   * 判断是否壳牌，或者是挖机的供应商壳牌。壳牌没有sapCode，只能这样判断了
   *
   * @return
   */
  public static boolean isShell(String orgId) {
    return SHELL_ORG_ID.equals(orgId) || SHELL_WJ_SUPPLIER_ORG_ID.equals(orgId);
  }

  public boolean isJCK(String orgId){
    return JCK_ORG_ID.equals(orgId);
  }

  /**
   * 判断是否随车
   * @param sapCode
   * @return
   */
  public static boolean isSCSapCode(String sapCode){
    if(StringUtils.isEmpty(sapCode)){
      return false;
    }
    return SC_SAP_CODE.equals(sapCode);
  }

  /**
   * @Des 判断是否重型
   * @Date 2021/6/1 11:12
   * @Author wangzhaoyu
   * @Param [sapCode]
   * @Return boolean
   */
  public static boolean isZXSapCode(String sapCode){
    if(StringUtils.isEmpty(sapCode)){
      return false;
    }
    return ZX_SAP_CODE.equals(sapCode);
  }

  public boolean isSC(String orgId){
    return SC_ORG_ID.equals(orgId);
  }

  public boolean isTJ(String orgId){
    return TJ_ORG_ID.equals(orgId);
  }

  public static boolean isTJSapCode(String sapCode){
    return TJ_SAP_CODE.equals(sapCode);
  }

  public static boolean isLvdaiSapCode(String sapCode){
    if(StringUtils.isEmpty(sapCode)){
      return false;
    }
    return LVDAI_SAP_CODE.equals(sapCode);
  }


  public boolean isYN(String orgId){
    if(StringUtils.isBlank(orgId)){
      return false;
    }
    return YN.equals(orgId);
  }

  public String ynOrgId(){
    return YN;
  }

}
